package com.ybu.controller;
import com.ybu.common.R;
import com.ybu.pojo.dto.RegisterDTO;
import com.ybu.pojo.dto.UserLoginDTO;
import com.ybu.pojo.vo.UserLoginVO;
import com.ybu.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api/user") // 访问的url的上级或者上两级目录
@Slf4j //日志的优先级默认是info
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("reg")
    public R<Void> register(@RequestBody @Validated RegisterDTO registerDTO) {
        log.debug("获取到的注册信息：{}", registerDTO);
        userService.register(registerDTO);
        return R.ok();
    }
    @PostMapping("login")
    public R<Object> login(@Validated @RequestBody UserLoginDTO userLoginDTO) {
        UserLoginVO userLoginVO = userService.login(userLoginDTO);
        //登录成功了
        return R.ok(userLoginVO);
    }
}
